﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace 畜牧业审核程序国产.Models.ToolsClass
{
    internal static class OnLoadingBarExecute
    {
        private static Timer _timer;
        private static IProgress<int> _progress;
        private static int _processedFiles = 0;
        private static readonly int Total = 3;
        
        public static void OnLoadingBar(IProgress<int> progress)
        {
            _progress = progress;
            int seconds = 0;
            
            int percentage = 0;
            Timer timer = new Timer();
            timer.Interval = 1000;
            timer.Elapsed += OnTimedEvent;
            timer.AutoReset = true; // 设置为自动重置以持续触发事件
            timer.Enabled = true;  // 启动计时器
                                 //timer每隔1秒钟触发一次,触发后,最后一秒的值重新计算
                                  
        }
       
        private static void OnTimedEvent(object? sender, ElapsedEventArgs e)
        {
            var 最后一秒 = DateTime.Now.Second % 4;
           var percentage = (int)((double)最后一秒 / Total * 100);
            _progress.Report(percentage);
        }
    }
}
